using System.Collections.Generic;
using Holoville.HOTween;
using Holoville.HOTween.Core;
using Holoville.HOTween.Plugins;
using UnityEngine;

public class ManagerLabelCoins : MonoBehaviour
{
	public static ManagerLabelCoins thisScript;

	public UILabel instLabel;

	public List<BonuseIcons> bonuseIconsList = new List<BonuseIcons>();

	public Color colorPlus;

	public Color colorMinus;

	private UILabel curLabelActiveForAdd;

	private MoneyType curCoinType;

	private TypeLabelBonuse curBonuseLabelType;

	private MoneyType _savedCoinType;

	private int _savedCount;

	private Queue<MessageBonuse> queueBonuseMessages = new Queue<MessageBonuse>();

	private void Awake()
	{
		thisScript = this;
	}

	public void AddLabelWithCoins(int countBonuse, TypeLabelBonuse bonuseType)
	{
		MessageBonuse messageBonuse = new MessageBonuse(bonuseType, countBonuse);
		if (curLabelActiveForAdd != null && bonuseType == curBonuseLabelType)
		{
			PereshetCoinsLabel(curLabelActiveForAdd, countBonuse);
		}
		else if (curLabelActiveForAdd != null)
		{
			queueBonuseMessages.Enqueue(messageBonuse);
		}
		else
		{
			FlyTextInstantiate(messageBonuse);
		}
	}

	public void FlyTextInstantiate(MessageBonuse messageBonuse)
	{
		UILabel component = ((GameObject)Object.Instantiate((Object)instLabel.gameObject)).GetComponent<UILabel>();
		if (BCWDebug.isDebugBuild)
		{
			BCWDebug.Log("newLabel=" + component);
		}
		UISprite component2 = component.transform.GetChild(0).GetComponent<UISprite>();
		foreach (BonuseIcons bonuseIcons in bonuseIconsList)
		{
			if (messageBonuse.bonuseType == bonuseIcons.bonuseType)
			{
				component2.spriteName = bonuseIcons.spriteName;
				component2.color = bonuseIcons.icoColor;
				component2.MakePixelPerfect();
			}
		}
		curBonuseLabelType = messageBonuse.bonuseType;
		curLabelActiveForAdd = component;
		curLabelActiveForAdd.transform.parent = base.transform;
		curLabelActiveForAdd.transform.localScale = new Vector3(1f, 1f, 1f);
		curLabelActiveForAdd.transform.localPosition = Vector3.zero;
		curLabelActiveForAdd.text = "0";
		PereshetCoinsLabel(curLabelActiveForAdd, messageBonuse.bonuseCount);
		curLabelActiveForAdd.alpha = 0f;
		curLabelActiveForAdd.gameObject.SetActive(true);
		StartMoveLabelCoins(curLabelActiveForAdd);
	}

	private void StartMoveLabelCoins(UILabel curLabel)
	{
		float num = 50f;
		float num2 = num / 100f;
		HOTween.To(curLabel, num2 * 0.4f, new TweenParms().Prop("alpha", 1f));
		HOTween.To(curLabel.gameObject.transform, 0.5f, new TweenParms().Prop("localPosition", new PlugVector3Y(curLabel.gameObject.transform.localPosition.y + 50f)).Ease(EaseType.Linear).OnComplete((TweenDelegate.TweenCallback)delegate
		{
			HideMoveLabelCoins(curLabel);
		}));
	}

	private void HideMoveLabelCoins(UILabel curLabel)
	{
		if (curLabelActiveForAdd.Equals(curLabel))
		{
			curLabelActiveForAdd = null;
			if (queueBonuseMessages.Count > 0)
			{
				FlyTextInstantiate(queueBonuseMessages.Dequeue());
			}
		}
		float num = 100f;
		float num2 = num / 100f;
		HOTween.To(curLabel, num2 * 0.3f, new TweenParms().Prop("alpha", 0f).Delay(num2 * 0.7f).Ease(EaseType.Linear));
		HOTween.To(curLabel.gameObject.transform, 1f, new TweenParms().Prop("localPosition", new PlugVector3Y(curLabel.gameObject.transform.localPosition.y + 100f)).Ease(EaseType.Linear).OnComplete((TweenDelegate.TweenCallback)delegate
		{
			RemoveLabelCoins(curLabel);
		}));
	}

	private void RemoveLabelCoins(UILabel curLabel)
	{
		HOTween.Kill(curLabel);
		Object.Destroy(curLabel.gameObject);
	}

	private void PereshetCoinsLabel(UILabel curLabel, int kolCoins)
	{
		if (!(curLabel == null))
		{
			int num = int.Parse(curLabel.text);
			num += kolCoins;
			if (num >= 0)
			{
				curLabel.text = string.Empty + num;
				curLabel.color = colorPlus;
			}
			else
			{
				curLabel.text = string.Empty + num;
				curLabel.color = colorMinus;
			}
		}
	}

	private void OnDestroy()
	{
		thisScript = null;
	}
}
